﻿angular.module("app").service('registerServece', function ($http, $location, $rootScope, httpRequestSvc, loginServece) {

    var baseUrl = "http://localhost:15930/api/Account/Register";

    var servise = {
        registerUser: registerUser
    };

    return servise;

    function onUserRegisterError(data) {
        alert("User Registered" + data);
    };

    function registerUser(userName, password, confirmPassword) {

        var user = {
            userName: userName,
            password: password,
            confirmPassword: confirmPassword
        };

        httpRequestSvc.postJson(baseUrl, user)
            .then(
                function (resevedData) {
                    return resevedData;
                },
                function (err) {
                    onUserRegisterError(err);
                })
            .then(
                function (data) {
                    if (data == "") {
                        {
                            console.log("from after succes register");
                            console.log(JSON.stringify(user.userName, null, 4));
                            console.log(JSON.stringify(user.password, null, 4));
                        }

                        //loginServece.loginUser(user.userName, password);
                    }
                },
                function (err) {
                    alert("Error logging");
                }
            );
    }
});